package com.ms.game.common.container;

import java.util.ArrayList;
import java.util.HashMap;

import com.ms.service.error.ErrorCode;

public class GameLimitInfo 
{
	private static GameLimitInfo instance;
	
	private  HashMap<String , GameAccClassify> dataMap;
	
	public  HashMap<String, GameAccClassify> getDataMap() {
		return dataMap;
	}

	public  void setDataMap(HashMap<String,GameAccClassify> dataMap) {
		this.dataMap = dataMap;
	}

	public static GameLimitInfo getInstance() {
		return instance;
	}

	public static void setInstance(GameLimitInfo instance) {
		GameLimitInfo.instance = instance;
	}
	
	
	//*****************回傳結果*************************
	//無此功能驗證
	public final static int NULL=-1;
	//不可使用
	public final static int FALSE = 0;
	//可使用
	public final static int TRUE = 1;
	//需要等級50 
	public final static int LV50 = 2;
	//需要認證   
	public final static int NEED_VERIFY = 3;
	//需要儲值  
	public final static int NEED_STORE_MONEY = 4;
	//需要註冊
	public final static int NEED_REGACC = 5;
	
	
	
	//*****************基本功能*************************
	public final static String BASIC_LV_UP = "BASIC_LV_UP";
	
	public final static String  BASIC_GAME_RECORD = "BASIC_GAME_RECORD";
	
	public final static String BASIC_GAME_NOTIFY = "BASIC_GAME_NOTIFY";
	
	public final static String BASIC_JP_NOTIFY = "BASIC_JP_NOTIFY";
	
	public final static String BASIC_MARQUEE = "BASIC_MARQUEE";
	
	public final static String BASIC_RANK = "BASIC_RANK";
	
	public final static String BASIC_NOOB_SHOW = "BASIC_NOOB_SHOW";
	
	public final static String BASIC_SYS_SETTING = "BASIC_SYS_SETTING";
	
	
	//*****************聊天相關*************************
	public final static String  CHAT_HOBON_SPONSOR = "CHAT_HOBON_SPONSOR";
	
	public final static String  CHAT_HOBON_DRAW = "CHAT_HOBON_DRAW";
	
	public final static String  CHAT_SECRET_TALK = "CHAT_SECRET_TALK";
	
	public final static String  CHAT_GROUP_TALK = "CHAT_GROUP_TALK";
	
	public final static String  CHAT_ADD_FREIND = "CHAT_ADD_FREIND";
	
	public final static String  CHAT_PUBLIC_TALK = "CHAT_PUBLIC_TALK";
	
	
	//*****************推廣*************************
	public final static String  PUSH_INVIT_FRIEND = "PUSH_INVIT_FRIEND";
	
	public final static String  PUSH_INVIT_CODE = "PUSH_INVIT_CODE";
	
	//*****************保箱箱*************************
	public final static String BANK_ATM = "BANK_ATM";
	
	public final static String BANK_SET_PASSWORD = "BANK_SET_PASSWORD";
	
	public final static String BANK_REWARD = "BANK_REWARD";
	
	
	//*****************儲值*************************
	public final static String BILLING_STORE_MONEY = "BILLING_STORE_MONEY";
	
	public final static String BILLING_TRANS_POINT = "BILLING_TRANS_POINT";
	
	//*****************交易*************************
	public final static String TRANS_SEND_GIFT = "TRANS_SEND_GIFT";
	
	public final static String TRANS_REV_GIFT = "TRANS_REV_GIFT";
	
	//*****************道具*************************
	public final static String ITEM_STONE_ROLL = "ITEM_STONE_ROLL";
	
	public final static String ITEM_UNLOCK = "ITEM_UNLOCK";
	
	public final static String ITEM_LVUPGRADE = "ITEM_LVUPGRADE";
	
	public final static String ITEM_USE = "ITEM_USE";
	
	
	
	
	//******************** only use by server ********************
	
	/**
	 * 確認玩家會員資格限制
	 * @param key
	 * @param vip
	 * @param lv
	 * @param isverify
	 * @return
	 */
	public static int checkLimitByClassify(String key , int vip , int lv , boolean isverify,boolean istrial,String invite)
	{
		HashMap<String , GameAccClassify> data = GameLimitInfo.getInstance().getDataMap();
		if(!data.containsKey(key))
		{
			return GameLimitInfo.NULL;
		}
		
		
		GameAccClassify classify = data.get(key);
		ArrayList<Integer> limit = null;
		
		//↓會員資格判斷↓
		//介紹碼
		if(vip == 0 && invite!=null && !invite.equals(""))
		{
			limit = classify.getIntro();
		}
		//己轉點末認證
		else if(vip > 0 &&  !isverify)
		{
			limit = classify.getTrans_no_verify();
		}
		//己轉點己認證
		else if(vip > 0 &&  isverify)
		{
			limit = classify.getTrans_verify();
		}
		//試玩 - 末轉點末認證
		else if(vip == 0 && !isverify && !istrial)
		{
			limit = classify.getFree_no_transandverify();
		}
		//試玩 - 末轉點己認證
		else if(vip == 0 && isverify)
		{
			limit = classify.getFree_notrans();
		}
		//立既玩
		else 
		{
			limit = classify.getFree_player();
		}
		
		if(limit==null)
		{
			return GameLimitInfo.NULL;
		}
		
		
		for(int token:limit)
		{
			switch(token)
			{
				case FALSE:
				{
					if(limit.size()==1)
					{
						return token;
					}
				}break;
				case TRUE:
				{
					if(limit.size()==1)
					{
						return token;
					}
				}break;
				case LV50:
				{
					if(lv <50)
					{
						return token;
					}
				}break;
				case NEED_VERIFY:
				{
					if(!isverify)
					{
						return token;
					}
				}break;
				case NEED_STORE_MONEY:
				{
					if(vip==0)
					{
						return token;
					}
				}break;
				case NEED_REGACC:
				{
					if(vip==0 && !isverify && invite==null)
					{
						return token;
					}
				}break;
			}
		}
		
		return TRUE;
	}
	
	/**
	 * 將判斷完的回傳結果 轉成 Error Code
	 */
	public static int limitToErrorCode(int limitCode){
		int errorCode = 0;
		switch (limitCode) {
		
		// 無此功能驗證
		case NULL:
			errorCode = ErrorCode.LIMIT_NOT_FOUND;
			break;
			
		// 不可使用
		case FALSE:
			errorCode = ErrorCode.NOT_VERIFIED_AND_NEED_FIRST_STORE;
			break;
			
		//可使用	
		case TRUE:
			errorCode = ErrorCode.SUCCESS;
			break;
			
		// 需要等級50
		case LV50:
			errorCode = ErrorCode.LEVEL_NEED_FIFTY;
			break;
			
		// 需要認證 NOT_VERIFIED_MEMBER = 27
		case NEED_VERIFY:
			errorCode = ErrorCode.NOT_VERIFIED;
			break;
			
		// 需要儲值
		case NEED_STORE_MONEY:
			errorCode = ErrorCode.NEED_FIRST_STORE;
			break;
			
		// 需要註冊
		case NEED_REGACC:
			errorCode = ErrorCode.NOT_REGISTERED; // *
			break;
			
		default:
			errorCode = ErrorCode.LIMIT_NOT_FOUND;
			break;
		}
		
		return errorCode;
	}
}

